package com.ccsoft.utils;

public class TimeUtils {
    private static final double DAY_SECONDS = 1 * 60 * 60 * 24;// 一天的秒数
    private static final double HOUR_SECONDS = 1 * 60 * 60;// 一小时的秒数
    private static final double MINUTE_SECONDS = 1 * 60;// 一分钟的秒数

    /**
     * 传入秒数，返回时间长度
     * xx天xx小时xx分钟xx秒
     * @param seconds
     * @return
     */
    public static String getTimeString(long seconds){
        int days = 0;
        int hours = 0;
        int minutes = 0;
        int remainSeconds = 0;
        if( seconds >= DAY_SECONDS )
            days = (int)(seconds / DAY_SECONDS);
        if( seconds >= HOUR_SECONDS )
            hours = (int)((seconds - days * DAY_SECONDS) / HOUR_SECONDS);
        if( seconds >= MINUTE_SECONDS )
            minutes = (int)((seconds - days * DAY_SECONDS - hours * HOUR_SECONDS) / MINUTE_SECONDS);

        remainSeconds = (int)(seconds - days * DAY_SECONDS - hours * HOUR_SECONDS - minutes * MINUTE_SECONDS);
        String ret = "";
        if( days > 0 )
            ret += days + "天";
        if( hours > 0 )
            ret += hours + "小时";
        if( minutes > 0 )
            ret += minutes + "分钟";
        if( remainSeconds > 0 )
            ret += remainSeconds + "秒";

        return ret;
    }
}
